﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Common;
using ElectrosLTD.Models;

namespace ElectrosLTD.Controllers
{
    public class PartialController : Controller
    {
        //
        // GET: /Partial/

        public ActionResult Index()
        {
            return View();
        }

        [ChildActionOnly]
        public ActionResult Comments(int productId)
        {
            List<Comment> commentList = new ProductServ.ProductWCFClient().GetProductComments(productId);
            return PartialView("Comments", commentList);
        }

        [ChildActionOnly]
        public ActionResult OrderDetails(Guid orderID)
        {
            List<ShoppingCartModel> orderList = new List<ShoppingCartModel>();
            List<OrderDetail> odList = new ProductServ.ProductWCFClient().GetAllOrdersDetails(orderID);

            foreach(OrderDetail od in odList)
            {
                ShoppingCartModel scm = new ShoppingCartModel();
                
                Product p = new ProductServ.ProductWCFClient().GetProductById(od.ProductId_FK);
                
                scm.productId = od.ProductId_FK;
                scm.productName = p.Name;
                scm.Image = p.Image;
                scm.Stock = od.Quantity;
                scm.Price = (decimal)p.Price;
                orderList.Add(scm);
            }
            return PartialView("OrderDetails", orderList);
        }
        
        [ChildActionOnly]
        public ActionResult Menu()
        {
            IEnumerable<Menu> menus = new ElectrosServ.ElectrosWCFClient().GetMenu(1).AsEnumerable();
            return PartialView("Menu", menus);
        }
    }
}
